package com.indoornavi.verbal.graph;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * A pair of edges
 * @author yaseen
 *
 */
public class Pair implements Comparable<Pair> {
	private String name;
	private Vertex vCentral;
	private Vertex vFirst;
	private Edge[] edges;
	private int weight;
	private int instruction;
	private boolean visited;
	private ArrayList<Edge> intermediateEdges;

	public static final int STRAIGHT = 1;
	public static final int RIGHT = 2;
	public static final int LEFT = 3;
	public static final int UP = 4;
	public static final int DOWN = 5;
	public static final int BACK = 6;
	
	
	/**
	 * Takes in central vertex to allow for 
	 * simpler, faster computations on mobile devices, 
	 * and for the creation of ad-hoc edges.
	 * Weight is set to NaN.
	 * @param name
	 * @param vCentral
	 * @param edge1
	 * @param edge2
	 */
	public Pair(String name, Vertex vCentral, Edge edges[]){
		this.name=name;
		this.vCentral = vCentral;
		this.vFirst = vCentral;
		this.edges = edges;
		visited=false;
		intermediateEdges = new ArrayList<Edge>();
//		weight=0;
	}
	
	/**
	 * Takes in central vertex to allow for 
	 * simpler, faster computations on mobile devices, 
	 * and for the creation of ad-hoc edges. 
	 * @param name
	 * @param vCentral
	 * @param edge1
	 * @param edge2
	 * @param weight
	 */
	public Pair(String name, Vertex vCentral, Edge edges[], int instruction, int weight){
		this.name=name;
		this.vCentral = vCentral;
		this.vFirst = vCentral;
		this.edges = edges;
		this.weight =weight;
		this.instruction=instruction;
		visited=false;
		intermediateEdges = new ArrayList<Edge>();
	}
	
	public void addIntermediateEdge(Edge e){
		intermediateEdges.add(e);
	}
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Vertex getvCentral() {
		return vCentral;
	}

	public void setvCentral(Vertex vCentral) {
		this.vCentral = vCentral;
	}
	
	public Vertex getvFirst(){
		return vFirst;
	}
	
	public void setvFirst(Vertex vFirst){
		this.vFirst = vFirst;
	}

	@Override
	public int compareTo(Pair arg0) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	public Edge[] getEdges(){
		if(edges.length==1)
			return new Edge[]{edges[0]};
		else
			return new Edge[]{edges[0], edges[1]};
	}
	
	public Edge getOtherEdge(Edge edge1){
		if(edge1 == null){
			System.out.println("edge1 is null");
		}
		if(edges == null){
			System.out.println("all of edges is null");
		}
		if(edges[0] == null){
			System.out.println("edges[0] is null");
			System.out.println("edges[1] is "+ edges[1].getName());
		}
		if(edges[1] == null){
			System.out.println("edges[1] is null");
			System.out.println("edges[0] is "+edges[0].getName());
		}
		try{
			if(edge1.getName().equals(edges[0].getName())){

				return edges[1];
			}
			else if(edge1.getName().equals(edges[1].getName())){
				return edges[0];
			}
			else{
				return null;
			}
		}
		catch(NullPointerException e){
			System.out.println("Error occurs in: "+ name);
		}
		
		return null;
	}
	
	public boolean hasEdge(Edge edge1){
		if(edge1.getName().equals(edges[0].getName()) || edge1.getName().equals(edges[1].getName())){
			return true;
		}
		else{
			return false;
		}
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int getInstruction() {
		return instruction;
	}

	public void setInstruction(int instruction) {
		this.instruction = instruction;
	}

	public boolean isVisited() {
		return visited;
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}

	public ArrayList<Edge> getIntermediateEdges() {
		return intermediateEdges;
	}
	
	public Edge getEdge(int index){
		return this.edges[index];
	}
	
	public void setEdges(Edge[] edges) {
		this.edges = edges;
	}
	
//	public Edge getEdge1() {
//		return edge1;
//	}
//
//	public void setEdge1(Edge edge1) {
//		this.edge1 = edge1;
//	}
//
//	public Edge getEdge2() {
//		return edge2;
//	}
//
//	public void setEdge2(Edge edge2) {
//		this.edge2 = edge2;
//	}
	
	
}
